import { pathToBase64 } from '@/tools/image-tools'
import { base64Upload } from '@/api/upload'

import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      suggestion:'',//建议反馈的内容
      imgList:[],
      imgList1:[],
      imageList2:[],
    };
  },
  computed:{
    ... mapGetters(['token'])
  },
  methods: {
    afterReadImgs(lists, name){
      this.imgList1 =lists
    },
    deleteImgs(index, lists, name) {
      this.imgList1  = lists
    },
    onUploadChange(list){
      this.$showLoading('图片上传中...')
      list.map((item,index)=>{
        const tempName = item?.file?.name??this.$moment().valueOf();
        pathToBase64(item.url).then(base64 =>{
          const fileStr = `${tempName},${base64}`
          base64Upload({
            fileStr,
          }).then(res=>{
            this.$showToast('上传图片成功')
            const {message, success} = res
            this.imageList2.push(this.$imageUrl+message)
            return  this.imageList2
          }).catch(err=>{
            console.log (err)})
        }).catch(error=>{
          console.log (error)
        })

      })
    },
    //删除数据
    onImgClear(){
      this.imgList = []
      this.imgList1 = []
      this.imageList2 = []
      this.$refs.uUpload.$refs.uUpload.clear()
    }
  }
}
